import socket
from threading import Thread
def createsocket(url,port):
    global sks
    for i in range(10000):
        try:
            sk = socket.socket()
            status = sk.connect((url, port))
            sk.send('连接成功'.encode('utf-8'))
            data = sk.recv(1024).decode('utf-8')
            print(data)
            sks.append(sk)
        except:
            print('无法连接服务器')
def sendmessage(sks):
    while True:
        for sk in sks:
            try:
                sk.send("发送数据".encode("utf-8"))
                print("发送成功")
            except:
                print("发送失败")
                sks.remove(sk)
                sk.close()
if __name__ == '__main__':
    sks=[]
    url="127.0.0.1"
    port=8000
    create_pool = Thread(target=createsocket, args=(url,port))
    send_pool = Thread(target=sendmessage, args=(sks))
    create_pool.start()
    send_pool.start()